package com.pengheng.server;

import io.netty.channel.Channel;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 连接通道处理类
 */
public class ChannelHandler {

    public static Map<String, Channel> channels = new ConcurrentHashMap<>();

    public static void writeAndFlush(String helloClient) {
        for (Map.Entry<String, Channel> socketAddressChannelEntry : channels.entrySet()) {
            socketAddressChannelEntry.getValue().writeAndFlush(helloClient);
        }
    }

    public static void writeAndFlush(String address, String helloClient) {
        Channel channel = channels.get(address);
        if (channel != null) {
            channel.writeAndFlush(helloClient);
        }
    }
}
